//
//  UIColor+CustomColor.h
//  FinanceProject
//
//  Created by 陈显摆 on 2025/1/15.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger , GradientApiDirection) {
    
    GradientApiDirectionLeftToRight,
    GradientApiDirectionTopToBotton,
};

@interface UIColor (CustomColor)

/*!
 *  返回一个RGBA格式的UIColor对象
 */
#define KRGBA(r, g, b, a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]

/*!
 *  返回一个RGB格式的UIColor对象
 */
#define KRGB(r, g, b) RGBA(r, g, b, 1.0f)

/*!
 *  从HEX字符串得到一个UIColor对象
 */
+ (UIColor *)hexColor:(NSString *)hexString;

+ (UIColor *)colorWithHexString:(NSString *)color alpha:(CGFloat)alpha;

/**
 * API: 根据传入的颜色和方向创建渐变
 */
+ (CAGradientLayer *)applyGradientWithColor1:(UIColor *)color1 color2:(UIColor *)color2 frame:(CGRect)frame direction:(GradientApiDirection)direction;

/*!
 *  获取字符，转换数据类型，改变部分字体颜色
 *
 *  @param string string
 *  @param start  开始位置
 *  @param length 截取长度
 *
 *  @return float
 */
+ (CGFloat)colorComponentFrom:(NSString *)string
                        start:(NSUInteger)start
                       length:(NSUInteger)length;

/*!
 *  从HEX数值得到一个UIColor对象
 */
+ (UIColor *)colorWithHex:(unsigned int)hex;

/*!
 *  从HEX数值和Alpha数值得到一个UIColor对象
 */
+ (UIColor *)colorWithHex:(unsigned int)hex
                    alpha:(float)alpha;

/*!
 *  创建一个随机UIColor对象
 */
+ (UIColor *)randomColor;

/*!
 *  从已知UIColor对象和Alpha对象得到一个UIColor对象
 */
+ (UIColor *)colorWithColor:(UIColor *)color
                      alpha:(float)alpha;

/*!
 *  UIColor 转UIImage
 *
 *  @param color color
 *
 *  @return UIColor 转UIImage
 */
+ (UIImage *)imageWithColor:(UIColor *)color;

/*!
 *  绘制渐变色
 *
 *  @param view 放在哪个view上
 *
 *  @return 渐变过后的layer
 */
+ (CAGradientLayer *)setGradualChangingColor:(UIView *)view fromColor:(NSString *)fromHexColorStr toColor:(NSString *)toHexColorStr;

/*!
 *  绘制渐变色 从上到下
 *
 *  @param view 放在哪个view上
 *
 *  @return 渐变过后的layer
 */
+ (CAGradientLayer *)setGradualTopBottomChangingColor:(UIView *)view fromColor:(NSString *)fromHexColorStr toColor:(NSString *)toHexColorStr;

/*!
 *  绘制渐变色
 *
 *  @param view 放在哪个view上
 *  @param frame 如果 setGradualChangingColor:fromColor:toColor: 由于圆角而尺寸不对 用这个 自定frame
 *
 *  @return 渐变过后的layer
 */
+ (CAGradientLayer *)setGradualChangingColor:(UIView *)view frame:(CGRect)frame fromColor:(NSString *)fromHexColorStr toColor:(NSString *)toHexColorStr;

/*!
 *  绘制渐变色 转成image
 *
 *  @param colors 两个颜色 或多个
 *
 *  @param rect from
 *
 *  @return 渐变过后的image
 */
+ (UIImage *)setGradientWithColors:(NSArray *)colors rect:(CGRect)rect;


@end

NS_ASSUME_NONNULL_END
